class Solution {
    public int search(int[] nums, int target) {
        int l = 0, r = nums.length-1;
        int ans = -1;
        while( l<=r ){
            int mid = (l+r) / 2;
            if( target>nums[mid] ){
                l = mid+1;
            }else{
                r = mid-1;
                ans = mid;
            }
        }
        if(ans==-1)
            return -1;
        return nums[ans]==target ? ans : -1;
    }
}